const topPresetBack = document.querySelector(".topPreset a")
topPresetBack.addEventListener("click", function () {
	history.back()
})

const carInfo = [
	{
		carNum: "3265489699900456",
		licensePlate: "京A42310",
		vehicleModel: "厢式货车",
		institution: "北京中转站",
		load: "2吨"
	},
	{
		carNum: "3092889699900852",
		licensePlate: "苏A87658",
		vehicleModel: "厢式货车",
		institution: "南京中转站",
		load: "5吨"
	},
	{
		carNum: "8945689699900753",
		licensePlate: "沪A72585",
		vehicleModel: "大型厢式货车",
		institution: "上海中转站",
		load: "6吨"
	},
	{
		carNum: "1659889699900526",
		licensePlate: "浙A35696",
		vehicleModel: "大型厢式货车",
		institution: "杭州中转站",
		load: "8吨"
	}
]

const info = document.querySelectorAll(".info ul li span")
const carImg = document.querySelector(".carImg ul")
Transform(carImg)
let endPoint = -5.5
new AlloyFinger(carImg, {
	touchEnd: function (evt) {
		if (endPoint > -176) {
			carImg.translateX = 0
			infoChange(0)
		} else if (endPoint > -528) {
			carImg.translateX = -350
			infoChange(1)
		} else if (endPoint > -883) {
			carImg.translateX = -700
			infoChange(2)
		} else {
			carImg.translateX = -1050
			infoChange(3)
		}
	},
	pressMove: function (evt) {
		carImg.translateX += evt.deltaX
		carImg.translateX > 0 && (carImg.translateX = 0)
		carImg.translateX < -1050 && (carImg.translateX = -1050)
		endPoint = carImg.translateX
	}
})

function infoChange(index) {
	info[0].innerText = carInfo[index].carNum
	info[1].innerText = carInfo[index].licensePlate
	info[2].innerText = carInfo[index].vehicleModel
	info[3].innerText = carInfo[index].institution
	info[4].innerText = carInfo[index].load
}
